package com.vegetable.modules.service.stock.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.common.utils.Query;
import com.vegetable.modules.entity.stock.AgentStock;
import com.vegetable.modules.mapper.stock.AgentStockMapper;
import com.vegetable.modules.service.stock.IAgentStockService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 代办库存表 服务实现类
 * </p>
 *
 * @author wangruijie
 * @since 2024-04-10
 */
@Slf4j
@Service
@AllArgsConstructor
public class AgentStockServiceImpl extends ServiceImpl<AgentStockMapper, AgentStock> implements IAgentStockService {

    /**
     * 代办库存列表查询
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        // 品名
        String commodityName = (String)params.get("commodityName");
        IPage<AgentStock> page = this.page(
                new Query<AgentStock>().getPage(params),
                new QueryWrapper<AgentStock>()
                        // 代办id
                        .eq(ObjectUtils.isNotEmpty(params.get("agentId")),"agent_id", params.get("agentId"))
                        .like(StringUtils.isNotBlank(commodityName),"commodity_name", commodityName)
                        .orderByDesc("order_time")
        );

        return new PageUtils(page);
    }
}
